<?php 
    $functions=$viewModel->get('functions');
?>
<div class="container-fluid" style="width:97%">
    <div class="row">
            <h2>Thêm nhóm quyền</h2>
            <hr>
            <form enctype="multipart/form-data" action="" method="post">
            <div class="col-md-6">
                <div class="panel panel-default">
                  <div class="panel-heading">Thông tin nhóm</div>
                    <div class="panel-body">
                    <div class="form-group">
                    <label class="label-control" for="tennhom">Tên nhóm</label>
                    <input type="text" class="form-control" name="TenNhom" id="tennhom"  placeholder="Nhập tên nhóm">
                    </div>
                     <div class="form-group">
                    <label class="label-control" for="mota">Mô tả</label>
                    <textarea class="form-control" name="MoTa" id="mota"></textarea>
                    </div>
                  </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="panel panel-default">
                    <div class="panel-heading">Chọn chức năng cho nhóm</div>
                    <div class="panel-body" style="overflow-y: auto; height:350px;">
                        <div class="checkbox">
                            <div>
                                <label>
                                    <input type="checkbox" onClick="toggle(this)" name="select-all" id="select-all" value="">
                                    Tất cả
                                </label>
                            </div>
                            <div class="child">
                            <?php foreach ($functions as $function) { ?>
                            <div>                           
                                <label>
                                    <input type="checkbox" name="check_list[]" value="<?php echo $function->Id; ?>">
                                    <?php echo $function->MoTa; ?>
                                </label>
                            </div>
                            <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div> 
            <div class="form-group form-inline clear text-center">
                <button name="save" type="submit" class="btn btn-success form-control">Lưu</button>
                <button class="btn btn-warning form-control" name="cancel"></a>Hủy</button>
               <!--  <?php
               /* if(isset($_POST['save'])){
                    $ids = array();
                    if(!isset($_POST['check_list']))
                        return;
                    foreach($_POST['check_list'] as $val){
                        $ids[] = (int) $val;
                    }
                    //$ids = implode(',', $ids);
                    echo "<pre>";
                    print_r($ids)
                    echo "</pre>";
                }*/
                ?> -->
            </div>
            </form>
    </div>
    </div>
    <script type="text/javascript">$('.list > li a').click(function() {
    $(this).parent().find('ul').toggle();
    });</script> 

     <script type="text/javascript">
    // $('#select-all').click(function(event) {   
    //     if(this.checked) {
    //         // Iterate each checkbox
    //         $(':checkbox').each(function() {
    //             this.checked = true;                        
    //         });
    //     }
    // });
   function toggle(source) {
  checkboxes = document.getElementsByName('check_list[]');
  for(var i=0, n=checkboxes.length;i<n;i++) {
    checkboxes[i].checked = source.checked;
  }
}
    // </script>